﻿using PLCS.Application.Contracts.EquipmentApp.Dtos;
using PLCS.Application.Contracts.ProcessApp.Dtos;
using PLCS.Client.IService.ProcessSolution;
using PLCS.Domain.Equipments;
using PLCS.Domain.Shared.Enums;

using System.Collections.ObjectModel;

using Volo.Abp.Application.Dtos;

namespace PLCS.Client.Service.ProcessSolution;

public class ProcessService : BaseService<ProcessDto, ProcessEditDto>, IProcessService
{
    public override async Task<IEnumerable<ProcessDto>> GetListAsync()
    {
        RequestParam requestParam = new(method: Method.Get, route: $"process/processList");
        var apiRes = await restClient.ExecuteAsync<ObservableCollection<ProcessDto>>(requestParam);
        if (apiRes.Status)
            return apiRes.Data;
        else
            return Enumerable.Empty<ProcessDto>();
    }

    public async Task<PagedResultDto<ProcessDto>> GetListBySearchAsync(int skipCount, int maxResultCount, string? processNo)
    {
        var route = $"process/bySearch?SkipCount={skipCount}&MaxResultCount={maxResultCount}";
        if (!string.IsNullOrEmpty(processNo))
            route += $"&processNo={processNo}";
        RequestParam requestParam = new(method: Method.Get, route: route);
        var apiRes = await restClient.ExecuteAsync<PagedResultDto<ProcessDto>>(requestParam);
        if (apiRes.Status)
            return apiRes.Data;
        else
            return new PagedResultDto<ProcessDto>();
    }

    public async Task<IEnumerable<TableDto>> GetTableNamesAsync()
    {
        RequestParam requestParam = new RequestParam(Method.Get, "process/tableNames");
        var result = await restClient.ExecuteAsync<IEnumerable<TableDto>>(requestParam);
        if (result.Status)
            return result.Data;
        else
            return Enumerable.Empty<TableDto>();
    }
}